<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Verify;  //使用验证码命名空间

class LoginController extends Controller {
    public function login(){
        $uid = $_COOKIE['wen_admin_userid'];
        if($uid){
            $this->redirect("index/index");
        }
    	$this->display();
        // unset($_SESSION["admin_userinfo"]);
    }
    //登陆校验
    public function check(){
    	$username = $_POST['username'];
    	$password = MD5($_POST['password']); 
        $vercode = $_POST['vercode'];
        //验证码验证
        $verify = new Verify();
        if($verify->check($vercode)){
            $re = M('adminuser')->where("username = '$username' and password = '$password'")->find();
            if($re){
                $_SESSION['admin_userinfo'.$re['id']] = $re;
                setcookie("wen_admin_userid",$re['id'],time()+5*60*60,'/');
                $now = time();
                M()->execute("update adminuser set logintime = $now where id = $re[id]");
                echojson('登陆成功',1);
            }else{
                echojson('用户名或密码错误',0);
            }
        }else{
            echojson('验证码错误',0);
   
        }
    	
    	// echo M()->getLastSql();
    }
    //验证码
    public function verify() {
        $config =    array(    
            'fontSize'    =>    90,    // 验证码字体大小   
            'length'      =>    4,     // 验证码位数   
            'codeSet'     => '0235689',
            'useNoise'    =>    false, // 关闭验证码杂点ture
        );
       
        $Verify = new Verify($config);
        $Verify->entry();
    }



}